using System;
using System.Data;
namespace CNDM.DB
{
    public class StoredProcedures
    {
        private MainDB _db;

        public StoredProcedures(MainDB db)
        {
            _db = db;
        }

        public MainDB Database
        {
            get { return _db; }
        }

        protected DataTable CreateDataTable(IDbCommand command)
        {
            return _db.CreateDataTable(command);
        }

        protected DataSet CreateDataSet(IDbCommand command)
        {
            return _db.CreateDataSet(command);
        }

        #region Category
        /// <summary>
        /// Lay danh sach cat theo channel. Neu Cat_ID = 0 thi lay het cat cha, con <> 0 thi lay cat con
        /// </summary>
        /// <param name="Cat_ParentID"></param>
        /// <param name="Channel"></param>
        /// <returns></returns>
        public DataTable XMobile_Category_SelectBy_CatParent(int @iCat_ParentID, string Channel_Name)
        {

            IDbCommand cmd = _db.CreateCommand("XMobile_Category_SelectBy_CatParent", true);
            _db.AddParameter(cmd, "iCat_ParentID", DbType.Int32, iCat_ParentID);
            _db.AddParameter(cmd, "Channel_Name", DbType.String, Channel_Name);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        /// <summary>
        /// Danh sach bai noi bat trang chu
        /// </summary>
        /// <param name="Top"></param>
        /// <returns></returns>
        public DataTable Get_NoiBatTrangChu(int Top)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_News_Select_NoiBatTrangChu", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, Top);            
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Lay cat theo cat url
        /// </summary>
        /// <param name="Cat_DisplayURL"></param>
        /// <returns></returns>

        public DataTable Xmobile_Select_Category_by_DisplayURL(string Cat_DisplayURL)
        {

            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_Category_by_DisplayURL", true);
           
            _db.AddParameter(cmd, "Cat_DisplayURL", DbType.String, Cat_DisplayURL);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        public DataTable Xmobile_Get_All_Category(string Channel_Name)
        {

            IDbCommand cmd = _db.CreateCommand("Xmobile_Get_All_Category", true);
            _db.AddParameter(cmd, "Channel_Name", DbType.String, Channel_Name);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        /// <summary>
        /// Lay danh sach tin noi bat
        /// </summary>
        /// <param name="Cat_ID"></param>
        /// <param name="Top"></param>
        /// <returns></returns>
        public DataTable Xmobile_Select_NewsPublished_IsFocus(string Cat_ID, string Top)
        {

            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_NewsPublished_IsFocus", true);

            _db.AddParameter(cmd, "Cat_ID", DbType.String, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.String, Top);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        #endregion

        #region News


        public DataTable Search_News(string KeySearch, int PageIndex, int PageSize)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_Search_News", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, KeySearch);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, PageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, PageSize);

            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Lay danh sach tin cu hon
        /// </summary>
        /// <param name="News_ID"></param>
        /// <param name="Top"></param>
        /// <param name="Cat_ID"></param>
        /// <returns></returns>
        public DataTable Get_DanhSachTinCu(Int64 News_ID, int Top, int Cat_ID)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_DanhSachTinCu", true);
            _db.AddParameter(cmd, "News_ID", DbType.Int64, News_ID);
            _db.AddParameter(cmd, "Cat_ID", DbType.Int32, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.Int32, Top);
           
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Danh sach tin moi
        /// </summary>
        /// <param name="News_ID"></param>
        /// <param name="Top"></param>
        /// <param name="Cat_ID"></param>
        /// <returns></returns>
        public DataTable Get_DanhSachTinMoi(Int64 News_ID, int Top, int Cat_ID)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_DanhSachTinMoi", true);
            _db.AddParameter(cmd, "News_ID", DbType.Int64, News_ID);
            _db.AddParameter(cmd, "Cat_ID", DbType.Int32, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.Int32, Top);

            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Tin chi tiet
        /// </summary>
        /// <param name="news_id"></param>
        /// <returns></returns>
        public DataTable Get_NewsDetail(Int64 news_id)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_News_Select_TinChiTiet", true);
            _db.AddParameter(cmd, "NewsID", DbType.Int64, news_id);
            
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Danh sach tin theo chyen muc
        /// </summary>
        /// <param name="News_ID"></param>
        /// <param name="Cat_ID"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public DataTable Get_DanhSachTin(string News_ID, string Cat_ID,	int PageIndex, int PageSize)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_DanhSachTin", true);
            _db.AddParameter(cmd, "News_ID", DbType.String, News_ID);
            _db.AddParameter(cmd, "Cat_ID", DbType.String, Cat_ID);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, PageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, PageSize);
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        /// <summary>
        /// Lay bai noi bat trang chu
        /// </summary>
        /// <param name="Cat_ID"></param>
        /// <param name="Top"></param>
        /// <param name="Mode"></param>
        /// <returns></returns>
        public DataTable Get_NoiBatChuyenMuc_TrangChu(int Cat_ID ,int Top, int Mode)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_News_Select_NoiBatChuyenMuc_Home", true);
            _db.AddParameter(cmd, "Cat_ID", DbType.Int32, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.Int32, Top);
            _db.AddParameter(cmd, "Mode", DbType.Int32, Mode);
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }


        /// <summary>
        /// Danh sach bai noi bat chuyen muc
        /// </summary>
        /// <param name="Cat_ID"></param>
        /// <param name="Top"></param>
        /// <returns></returns>
        public DataTable Get_NoiBatChuyenMuc(int Cat_ID, int Top)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_Select_NewsPublished_IsFocus", true);

            _db.AddParameter(cmd, "Cat_ID", DbType.String, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.String, Top);
            DataTable table = _db.CreateDataTable(cmd);
            return table;
           
            
        }

        /// <summary>
        /// Danh sach tin moi nhat
        /// </summary>
        /// <param name="Cat_ID">ID Chuyen muc ( 0 : lat tat cac cac chuyen muc)</param>
        /// <param name="Top">So luong tin can lay ra</param>
        /// <returns></returns>
        public DataTable Get_TinMoiNhat(int Cat_ID, int Top)
        {
            IDbCommand cmd = _db.CreateCommand("Xmobile_News_Select_News_New", true);

            _db.AddParameter(cmd, "Cat_ID", DbType.String, Cat_ID);
            _db.AddParameter(cmd, "Top", DbType.String, Top);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        #endregion

    }
}